{extend name="admin@index_layout"/}
{block name="main"}
<style type="text/css">
    .childrenBody {
        background: #fff;
    }
</style>

<div class="layui-card">
    <div class="layui-card-header">陪诊服务列表</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="currentTable" lay-filter="currentTable"></table>
    </div>
</div>

<script type="text/html" id="picTpl">
    <img style="max-width:80px; max-height:30px;" src="{{d.icon_img}}" data-image="{{d.name}}">
</script>
<script type="text/html" id="picTpl2">

    <img style="max-width:80px; max-height:30px;" src="{{d.bc_img}}" data-image="{{d.name}}">

</script>

<script type="text/html" id="statusTypeTpl">
    <input type="checkbox" name="status" data-href='{:url("setstate2")}?id={{d.id}}' value="{{d.id}}" lay-skin="switch"
           lay-text="通过|待审核" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="barTool">

    <a class="layui-btn layui-btn-xs" data-open='{:url("editareap")}?id={{ d.id }}' data-title="编辑内容"
       data-full="true">编辑</a>

    <a href='{:url("delareap")}?ids={{ d.id }}'
       class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
</script>


{/block}
{block name="script"}
<script>
    layui.use(['table', 'yznTable'], function () {
        var table = layui.yznTable;

        var init = {
            table_elem: '#currentTable',
            add_url: "{:url('addareap',['server_id'=>$server_id])}?server_id={$server_id}",
            delete_url: "{:url('del',['catid'=>$catid])}",
            modify_url: '{:url("listorder",["catid"=>$catid])}',
        };
        var cate_list = {:json_encode($proviec)};
        table.render({
            init: init,
            id: 'currentTable',
            elem: '#currentTable',
            url: '{:url("areap")}?id={$server_id}',
            // searchFormTpl:,
            toolbar: ['refresh',
                [{
                    text: '添加',
                    url: init.add_url,
                    method: 'open',
                    icon: 'iconfont icon-add',
                    class: 'layui-btn layui-btn-normal layui-btn-sm',
                    extend: 'data-full="true"',
                }],
            ],
            cols: [
                [
                    {field: 'id', width: '10%', align: "center", title: 'ID', search: false},
                    {field: 'province', align: "center", width: '20%', title: '省', selectList: cate_list},
                    {field: 'city', align: "center", width: '20%', title: '市', selectList: {}},
                    {
                        field: 'status',
                        width: '10%',
                        align: "center",
                        title: '状态',
                        templet: '#statusTypeTpl',
                        unresize: true,
                        selectList: {0: '隐藏', 1: '显示'}
                    },
                    {field: 'price', align: "center", width: '20%', title: '价格', search: false},
                    {fixed: 'right', align: "center", width: '20%', title: '操作', toolbar: '#barTool'}
                ]
            ],
            page: {}
        });
        yznTable.bindevent();
        selectElement = document.getElementById('c-province');
        selectElement.setAttribute("lay-filter", "c-province");
        form1();
        selectElement2 = document.getElementById('searchFieldset_currentTable');
        selectElement2.classList.remove("layui-hide");
        var element = document.getElementById('layui-input-search');
        element.parentNode.removeChild(element);
    });

    function form1(){
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(c-province)', function (data) {
                console.log(data.value);
                $.ajax({
                    type: "POST",//规定传输方式
                    url: "{:url('getc_cate')}",//提交URL
                    data: {'id':data.value},//提交的数据
                    success: function(result){
                        if(result.code == 200){
                            $("#c-city").empty();
                            var str = "<option value>- 全部 -</option>";
                            $.each(result.data, function(i, val){
                                str += '<option value='+val.id+'>'+val.name+'</option>'
                            });
                            $("#c-city").append(str);
                            layui.form.render('select');
                        }
                    },
                    error: function() {
                        alert("获取信息失败")
                    }
                });
            })
        });
    }
</script>
{/block}